//
//  MBProgressHUD+Add.m
//  视频客户端
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+Add.h"
#import "AppDelegate.h"

@implementation MBProgressHUD (Add)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.cornerRadius = 2;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    hud.detailsLabelText = text;
    hud.color = SC_RGB(46, 46, 46);
    UIView *view_v = [[UIView alloc] init];
    view_v.bounds = CGRectMake(0, 0, 30, 40);
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:icon]];
    imgView.frame = CGRectMake(0, 0, 30, 30);
    [view_v addSubview:imgView];
    hud.customView = view_v;
    
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    if(!view)view = ((AppDelegate*)[UIApplication sharedApplication].delegate).window;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.cornerRadius = 2;
    hud.color = SC_RGB(46, 46, 46);
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    hud.detailsLabelText = message;
  
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    return hud;
}

- (void)switchShowError:(NSString *)error {
    UIView *view = [[UIView alloc] init];
    view.bounds = CGRectMake(0, 0, 30, 40);
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hud_error"]];
    imgView.frame = CGRectMake(0, 0, 30, 30);
    [view addSubview:imgView];
    self.customView = view;
    self.mode = MBProgressHUDModeCustomView;
    self.detailsLabelText = error;
    [self hide:YES afterDelay:2];
}

- (void)switchShowSuccess:(NSString *)success {
    UIView *view = [[UIView alloc] init];
    view.bounds = CGRectMake(0, 0, 30, 40);
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hud_success"]];
    imgView.frame = CGRectMake(0, 0, 30, 30);
    [view addSubview:imgView];
    self.customView = view;
    self.mode = MBProgressHUDModeCustomView;
    self.detailsLabelText = success;
    [self hide:YES afterDelay:1];
}

- (void)switchShowTip:(NSString *)tip {
    UIView *view = [[UIView alloc] init];
    view.bounds = CGRectMake(0, 0, 30, 40);
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hud_tip"]];
    imgView.frame = CGRectMake(0, 0, 30, 30);
    [view addSubview:imgView];
    self.customView = view;
    self.mode = MBProgressHUDModeCustomView;
    self.detailsLabelText = tip;
    [self hide:YES afterDelay:1];
}

+ (void)showError:(NSString *)error {
    [self showError:error toView:nil];
}

+ (void)showError:(NSString *)error toView:(UIView *)view {
    [self show:error icon:@"hud_error" view:view];
}

+ (void)showSuccess:(NSString *)success {
    [self showSuccess:success toView:nil];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view {
    [self show:success icon:@"hud_success" view:view];
}

+ (void)showTip:(NSString *)tip {
    [self showTip:tip toView:nil];
}

+ (void)showTip:(NSString *)tip toView:(UIView *)view {
    [self show:tip icon:@"hud_tip" view:view];
}

+ (void)showPlainText:(NSString *)text {
    [self showPlainText:text toView:nil];
}

+ (void)showPlainText:(NSString *)text toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.color = SC_RGB(46, 46, 46);
    hud.cornerRadius = 2;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    hud.detailsLabelText = text;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
}

@end
